package com.mobisys.live.controller;

import com.mobisys.live.bean.UserSigBean;
import com.mobisys.live.bean.im_group.CreateIMGroup;
import com.mobisys.live.im.TlsSignature;
import com.mobisys.live.response.Response;
import com.mobisys.live.util.SignUtil;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

import static com.mobisys.live.config.ResponseCode.*;

/**
 * Created by zhuo on 2018-01-16.
 */
@RestController
public class IMGroupController {

    /**
     * 创建聊天室群组
     * @param httpServletRequest
     * @param createIMGroup
     * @return
     */
    @RequestMapping(value = "/live/createGroup",method= RequestMethod.POST)
    public Response createGroup(@RequestBody CreateIMGroup createIMGroup, HttpServletRequest httpServletRequest){
        Response response=new Response();



        return response;
    }

  /*  @RequestMapping(value = "/live/enterGroup",method= RequestMethod.POST)
    public Response enterGroup(@RequestBody , HttpServletRequest httpServletRequest){
        Response response=new Response();


        return response;
    }*/


    @RequestMapping(value = "/0.1/im/sig",method= RequestMethod.GET)
    public Response getUserSig(@RequestParam String userId, HttpServletRequest httpServletRequest){
        Response response=new Response();
        if(userId==null){
            response.setRetureValue(INPUT_IS_INVALID);
            response.setRetureMsg(MSG_INPUT_IS_INVALID);
            return response;
        }
        String userSig=TlsSignature.genTLSSig(userId);
        if(userId==null||userId.equals("")){
            response.setRetureValue(CREATE_SIG_ERROR);
            response.setRetureMsg(MSG_CREATE_SIG_ERROR);
            return response;
        }

        UserSigBean userSigBean=new UserSigBean();
        userSigBean.setUserSig(userSig);
        response.setRetureValue(SUCCESS);
        response.setRetureMsg(MSG_SUCCESS);
        response.setRetureData(userSigBean);

        return response;
    }
}
